<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Freetype OpenGL: Texture atlas</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="style.css" rel="stylesheet" type="text/css" />



</head>
<body>
<div id="content"><!-- do not remove this div! -->

<div id="top"><!-- do not remove this div! -->

  
  <div id="titlearea">
    
    <div id="projectname">Freetype OpenGL</div>
    
    
    <div id="projectbrief">A high quality OpenGL text rendering engine for C</div>
    
  </div>
  

<!--

<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Freetype OpenGL
   &#160;<span id="projectnumber">0.1</span>
   </div>
   <div id="projectbrief">A high quality OpenGL text rendering engine for C</div>
  </td>
  
  
  
   
  
 </tr>
 </tbody>
</table>
</div>
-->


<!-- Generated by Doxygen 1.8.0 -->
<script type="text/javascript" src="dynsections.js"></script>
</div>
<div class="header">
  <div class="summary">
<a href="#nested-classes">Data Structures</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">Texture atlas</div>  </div>
</div><!--header-->
<div class="contents">
<hr/><a name="details" id="details"></a><h2>Synopsis</h2>
<p>A texture atlas is used to pack several small regions into a single texture. </p>
<p>The actual implementation is based on the article by Jukka Jylänki : "A Thousand Ways to Pack the Bin - A Practical Approach to Two-Dimensional Rectangle Bin Packing", February 27, 2010. More precisely, this is an implementation of the Skyline Bottom-Left algorithm based on C++ sources provided by Jukka Jylänki at: <a href="http://clb.demon.fi/files/RectangleBinPack/">http://clb.demon.fi/files/RectangleBinPack/</a></p>
<p>Example Usage: </p>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &quot;<a class="code" href="texture-atlas_8h.html">texture-atlas.h</a>&quot;</span>

 ...

 <span class="comment">/* Creates a new atlas of 512x512 with a depth of 1 */</span>
 <a class="code" href="structtexture__atlas__t.html" title="A texture atlas is used to pack several small regions into a single texture.">texture_atlas_t</a> * atlas = <a class="code" href="group__texture-atlas.html#ga7769be70f630e0a8a8b320525a07382d" title="Creates a new empty texture atlas.">texture_atlas_new</a>( 512, 512, 1 );

 <span class="comment">/* Allocates a region of 20x20 */</span>
 <a class="code" href="unionivec4.html" title="Tuple of 4 ints.">ivec4</a> region = <a class="code" href="group__texture-atlas.html#ga97c3b768599f7caebac33292619421ca" title="Allocate a new region in the atlas.">texture_atlas_get_region</a>( atlas, 20, 20 );

 <span class="comment">/* Fill region with some data */</span>
 <a class="code" href="group__texture-atlas.html#gafd130ce3015e5120ab62669ccdc7552d" title="Upload data to the specified atlas region.">texture_atlas_set_region</a>( atlas, region.<a class="code" href="unionivec4.html#a23145e2d274c7f165dec8e83bb80f690" title="Alias for first component.">x</a>, region.<a class="code" href="unionivec4.html#af31284e1d1a00ab2baf19c1290e90352" title="Alias for second component.">y</a>, region.<a class="code" href="unionivec4.html#a9d0e4978d049ba65b2165217953552f2" title="Alias for third component.">width</a>, region.<a class="code" href="unionivec4.html#afee981dd94e13fdfb8a5f737da9efc0a" title="Alias for fourth component.">height</a>, data, stride )

 ...
</pre></div> <table class="memberdecls">
<tr><td colspan="2"><h2><a name="nested-classes"></a>
Data Structures</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">struct &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a></td></tr>
<tr class="memdesc:"><td class="mdescLeft">&#160;</td><td class="mdescRight">A texture atlas is used to pack several small regions into a single texture.  <a href="structtexture__atlas__t.html#details">More...</a><br/></td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr class="memitem:ga7769be70f630e0a8a8b320525a07382d"><td class="memItemLeft" align="right" valign="top"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__texture-atlas.html#ga7769be70f630e0a8a8b320525a07382d">texture_atlas_new</a> (const size_t width, const size_t height, const size_t depth)</td></tr>
<tr class="memdesc:ga7769be70f630e0a8a8b320525a07382d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Creates a new empty texture atlas.  <a href="#ga7769be70f630e0a8a8b320525a07382d"></a><br/></td></tr>
<tr class="memitem:gac3fc1f3aaa1a18945bd1883aa18fb7ef"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__texture-atlas.html#gac3fc1f3aaa1a18945bd1883aa18fb7ef">texture_atlas_delete</a> (<a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *self)</td></tr>
<tr class="memdesc:gac3fc1f3aaa1a18945bd1883aa18fb7ef"><td class="mdescLeft">&#160;</td><td class="mdescRight">Deletes a texture atlas.  <a href="#gac3fc1f3aaa1a18945bd1883aa18fb7ef"></a><br/></td></tr>
<tr class="memitem:ga9200360ad560fca395e20ca80463dfd8"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__texture-atlas.html#ga9200360ad560fca395e20ca80463dfd8">texture_atlas_upload</a> (<a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *self)</td></tr>
<tr class="memdesc:ga9200360ad560fca395e20ca80463dfd8"><td class="mdescLeft">&#160;</td><td class="mdescRight">Upload atlas to video memory.  <a href="#ga9200360ad560fca395e20ca80463dfd8"></a><br/></td></tr>
<tr class="memitem:ga97c3b768599f7caebac33292619421ca"><td class="memItemLeft" align="right" valign="top"><a class="el" href="unionivec4.html">ivec4</a>&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__texture-atlas.html#ga97c3b768599f7caebac33292619421ca">texture_atlas_get_region</a> (<a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *self, const size_t width, const size_t height)</td></tr>
<tr class="memdesc:ga97c3b768599f7caebac33292619421ca"><td class="mdescLeft">&#160;</td><td class="mdescRight">Allocate a new region in the atlas.  <a href="#ga97c3b768599f7caebac33292619421ca"></a><br/></td></tr>
<tr class="memitem:gafd130ce3015e5120ab62669ccdc7552d"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__texture-atlas.html#gafd130ce3015e5120ab62669ccdc7552d">texture_atlas_set_region</a> (<a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *self, const size_t x, const size_t y, const size_t width, const size_t height, const unsigned char *data, const size_t stride)</td></tr>
<tr class="memdesc:gafd130ce3015e5120ab62669ccdc7552d"><td class="mdescLeft">&#160;</td><td class="mdescRight">Upload data to the specified atlas region.  <a href="#gafd130ce3015e5120ab62669ccdc7552d"></a><br/></td></tr>
<tr class="memitem:gafc00ed05e30dd34ed70f6d775e441845"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="group__texture-atlas.html#gafc00ed05e30dd34ed70f6d775e441845">texture_atlas_clear</a> (<a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *self)</td></tr>
<tr class="memdesc:gafc00ed05e30dd34ed70f6d775e441845"><td class="mdescLeft">&#160;</td><td class="mdescRight">Remove all allocated regions from the atlas.  <a href="#gafc00ed05e30dd34ed70f6d775e441845"></a><br/></td></tr>
</table>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="gafc00ed05e30dd34ed70f6d775e441845"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="group__texture-atlas.html#gafc00ed05e30dd34ed70f6d775e441845">texture_atlas_clear</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *&#160;</td>
          <td class="paramname"><em>self</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Remove all allocated regions from the atlas. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">self</td><td>a texture atlas structure </td></tr>
  </table>
  </dd>
</dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="demo-atb-agg_8c-example.html#a28">demo-atb-agg.c</a>.</dd>
</dl>
</div>
</div>
<a class="anchor" id="gac3fc1f3aaa1a18945bd1883aa18fb7ef"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="group__texture-atlas.html#gac3fc1f3aaa1a18945bd1883aa18fb7ef">texture_atlas_delete</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *&#160;</td>
          <td class="paramname"><em>self</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Deletes a texture atlas. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">self</td><td>a texture atlas structure </td></tr>
  </table>
  </dd>
</dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="demo-display-list_8c-example.html#a27">demo-display-list.c</a>.</dd>
</dl>
</div>
</div>
<a class="anchor" id="ga97c3b768599f7caebac33292619421ca"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="unionivec4.html">ivec4</a> <a class="el" href="group__texture-atlas.html#ga97c3b768599f7caebac33292619421ca">texture_atlas_get_region</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *&#160;</td>
          <td class="paramname"><em>self</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>width</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>height</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Allocate a new region in the atlas. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">self</td><td>a texture atlas structure </td></tr>
    <tr><td class="paramname">width</td><td>width of the region to allocate </td></tr>
    <tr><td class="paramname">height</td><td>height of the region to allocate </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns:</dt><dd>Coordinates of the allocated region </dd></dl>

</div>
</div>
<a class="anchor" id="ga7769be70f630e0a8a8b320525a07382d"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a>* <a class="el" href="group__texture-atlas.html#ga7769be70f630e0a8a8b320525a07382d">texture_atlas_new</a> </td>
          <td>(</td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>width</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>height</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>depth</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Creates a new empty texture atlas. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">width</td><td>width of the atlas </td></tr>
    <tr><td class="paramname">height</td><td>height of the atlas </td></tr>
    <tr><td class="paramname">depth</td><td>bit depth of the atlas </td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns:</dt><dd>a new empty texture atlas. </dd></dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="demo-atb-agg_8c-example.html#a42">demo-atb-agg.c</a>, <a class="el" href="demo-benchmark_8c-example.html#a31">demo-benchmark.c</a>, <a class="el" href="demo-cartoon_8c-example.html#a22">demo-cartoon.c</a>, <a class="el" href="demo-console_8c-example.html#a8">demo-console.c</a>, <a class="el" href="demo-display-list_8c-example.html#a23">demo-display-list.c</a>, <a class="el" href="demo-distance-field_8c-example.html#a3">demo-distance-field.c</a>, <a class="el" href="demo-font_8c-example.html#a25">demo-font.c</a>, <a class="el" href="demo-outline_8c-example.html#a28">demo-outline.c</a>, and <a class="el" href="demo-texture_8c-example.html#a1">demo-texture.c</a>.</dd>
</dl>
</div>
</div>
<a class="anchor" id="gafd130ce3015e5120ab62669ccdc7552d"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="group__texture-atlas.html#gafd130ce3015e5120ab62669ccdc7552d">texture_atlas_set_region</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *&#160;</td>
          <td class="paramname"><em>self</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>x</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>y</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>width</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>height</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const unsigned char *&#160;</td>
          <td class="paramname"><em>data</em>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">const size_t&#160;</td>
          <td class="paramname"><em>stride</em>&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Upload data to the specified atlas region. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">self</td><td>a texture atlas structure </td></tr>
    <tr><td class="paramname">x</td><td>x coordinate the region </td></tr>
    <tr><td class="paramname">y</td><td>y coordinate the region </td></tr>
    <tr><td class="paramname">width</td><td>width of the region </td></tr>
    <tr><td class="paramname">height</td><td>height of the region </td></tr>
    <tr><td class="paramname">data</td><td>data to be uploaded into the specified region </td></tr>
    <tr><td class="paramname">stride</td><td>stride of the data </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="ga9200360ad560fca395e20ca80463dfd8"></a>
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="group__texture-atlas.html#ga9200360ad560fca395e20ca80463dfd8">texture_atlas_upload</a> </td>
          <td>(</td>
          <td class="paramtype"><a class="el" href="structtexture__atlas__t.html">texture_atlas_t</a> *&#160;</td>
          <td class="paramname"><em>self</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Upload atlas to video memory. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">self</td><td>a texture atlas structure </td></tr>
  </table>
  </dd>
</dl>
<dl><dt><b>Examples: </b></dt><dd><a class="el" href="demo-distance-field_8c-example.html#a10">demo-distance-field.c</a>.</dd>
</dl>
</div>
</div>
</div><!-- contents -->
</div>
</body>
</html>
